﻿using System;

namespace net.xBei.Models.Request {
    /// <summary>
    /// 搜索列表
    /// </summary>
    public class SearchRequest {
        /// <summary>
        /// 页面
        /// </summary>
        public int? Page { get; set; } = 1;
        /// <summary>
        /// 分页大小
        /// </summary>
        public int? PageSize { get; set; } = 10;
        /// <summary>
        /// 搜索关键字
        /// </summary>
        public string? Key { get; set; }
        /// <summary>
        /// 客户端请求ID，服务器会直接原样返回
        /// </summary>
        public string? RequestId { get; set; }
        /// <summary>
        /// 跳过
        /// </summary>
        public int Skip() {
            return (Math.Max(1, Page ?? 1) - 1) * Math.Max(1, PageSize ?? 10);
        }
        /// <summary>
        /// 分页大小
        /// </summary>
        /// <returns></returns>
        public int GetLimit() {
            return PageSize ?? 10;
        }
        /// <summary>
        /// 修正参数
        /// </summary>
        public void FixParameter() {
            if (Key != null) { Key = Key.Trim(); }
            if (RequestId != null) { RequestId = RequestId.Trim(); }

        }
    }
    /// <summary>
    /// 按时间范围搜索列表。
    /// 默认搜索条件是<see cref="Begin"/> &lt;= 时间字段 &lt; <see cref="End"/>
    /// </summary>
    public class SearchByDateRangeRequest : SearchRequest {
        /// <summary>
        /// 起始时间（unix时间戳），默认搜索条件是<see cref="Begin"/> &lt;= 时间字段 &lt; <see cref="End"/>
        /// </summary>
        public long? Begin { get; set; }
        /// <summary>
        /// 结束时间（unix时间戳），默认搜索条件是<see cref="Begin"/> &lt;= 时间字段 &lt; <see cref="End"/>
        /// </summary>
        public long? End { get; set; }
    }
}
